<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\business\EhrHelper;
use yii\helpers\ArrayHelper;
use common\consts\CommonResources;
use kartik\select2\Select2;
use yii\web\JsExpression;

/* @var $this yii\web\View */
/* @var $searchModel common\models\kingdee\PersonPositionSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('kingdee', 'Person Positions');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="person-position-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('app', 'Create Person Position'), ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?php
    try {
        $gv = GridView::widget([
            'tableOptions' => ['class' => 'table table-condensed table-bordered table-striped table-hover'],
            'pager' => [
//            'class'          => GoPager::className(),
                'nextPageLabel' => Yii::t('app', 'Next Page'),
                'prevPageLabel' => Yii::t('app', 'Previous Page'),
                'firstPageLabel' => Yii::t('app', 'First Page'),
                'lastPageLabel' => Yii::t('app', 'Last Page'),
                'options' => [
                    'class' => 'pagination pagination-sm m-t-none m-b-none',
                ],
            ],
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => [
                [
                    'class' => 'yii\grid\SerialColumn',
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 25px;'],
                ],

//            'FID',
//            'FJOINDATE',
//            'FTRYOUTMONTH',
//            'FQUITDATE',
//            'FFORMALDATE',
//             'FCREATORID',
//             'FCREATETIME',
//             'FLASTUPDATEUSERID',
//             'FLASTUPDATETIME',
                [
                    'label' => Yii::t('app', 'Employee'),
                    'attribute' => 'FPERSONID',
                    'value' => function ($model) {
                        return Html::a(EhrHelper::getPersonNameById($model['FPERSONID']), [
                            '/kingdee/person/view',
                            'id' => $model['FPERSONID'],
                        ],
                            ['target' => '_blank']);
                    },
                    'format' => 'raw',
                    'filter' => Select2::widget([
                        'model' => $searchModel,
                        'attribute' => 'FPERSONID',
//                    'data' => ArrayHelper::map(\common\models\kingdee\Person::find()->select([
//                        'id' => 'FID',
//                        'text' => 'FNAME_L2'
//                    ])->asArray()->all(), 'id', 'text'),
//                    'options' => ['placeholder' => CommonResources::PROMPT_PLS_SELECT()],
//                    'pluginOptions' => [
//                        'allowClear' => true
//                    ],

                        'options' => [
                            'class' => 'form-control drop-search',
                            'placeholder' => Yii::t('app', \common\consts\CommonResources::PROMPT_PLS_SELECT()),
                        ],
                        'pluginOptions' => [
                            'minimumInputLength' => 1,
                            'allowClear' => true,
                            'language' => [
                                'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
                            ],
                            'ajax' => [
                                'url' => '/kingdee/person/json-all',
                                'dataType' => 'json',
                                'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                            ],
                            'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                            'templateResult' => new JsExpression('function(res) { return res.text; }'),
                            'templateSelection' => new JsExpression('function (res) { return res.text; }'),
                        ],
                    ]),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 200px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 200px;'],
                ],
//             'FJOINGROUPDATE',
//             'FBASEDATE',
//             'FJOINGROUPYEARS',
//             'FJOINCOMPANYYEARS',
//             'FJOINBASEYEARS',
//             'FHRORGUNITID',
//             'FCONTROLUNITID',
//            'FWORKTIME:datetime',
//            'FJOBGRADE',

                [
                    'label' => Yii::t('app', 'Enter Date'),
                    'attribute' => 'FENTERDATE',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],

                [
                    'label' => Yii::t('app', 'Left Date'),
                    'attribute' => 'FLEFTDATE',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],

//             'FISENROLLAGAIN',
//            [
//                'label' => Yii::t('app', 'Is Enroll Again'),
//                'attribute' => 'FISENROLLAGAIN',
//                'value' => function ($model, $key, $index, $column) {
//                    return EhrHelper::getYesOrNoByIntValue($model['FISENROLLAGAIN']);
//                },
//                'filter' => EhrHelper::getYesOrNo_map(),
//                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
//                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
//            ],

//             'FPERSONDEP',
                [
                    'label' => Yii::t('app', 'Person Department'),
                    'attribute' => 'FPERSONDEP',
                    'value' => function ($model) {
                        return Html::a(EhrHelper::getOrgAdminById($model['FPERSONDEP']), [
                            '/kingdee/org-admin/view',
                            'id' => $model['FPERSONDEP'],
                        ],
                            ['target' => '_blank']);
                    },
                    'format' => 'raw',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                ],
//             'FJOBLEVELID',
//             'FJOBSTARTDATE',
//             'FISHAVEWORK',
//             'FISHIGHEST',
//            'FZHUANYJSZW',
                [
                    'label' => Yii::t('app', 'Position'),
                    'attribute' => 'FPRIMARYPOSITIONID',
                    'value' => function ($model) {
                        return Html::a(EhrHelper::getOrgPositionById($model['FPRIMARYPOSITIONID']), [
                            '/kingdee/org-position/view',
                            'id' => $model['FPRIMARYPOSITIONID'],
                        ],
                            ['target' => '_blank']);
                    },
                    'format' => 'raw',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                ],
//            'FHIGHESTDEGREEDATE',
//            'FJOBGRADEENDDATE',
//            'FGKADMINID',
//            'FISADMIN',
//            'FISTECH',
//            'FHIGHESTPDEGREEID',
//            'FOLDPERSONDEPID',
//            'FJOINSYSTEMDATE',
//            'FADJUSTSYSVALUE',
//            'FADJUSTWORKVALUE',
//            'FADJUSTCOVALUE',
//            'FADJUSTGROUPVAL',
//            'FSYSSERVICEYEARS',

//            'FENROLLSOURCEID',
                [
                    'attribute' => 'FENROLLSOURCEID',
                    'label' => Yii::t('app', 'Enroll Source'),
                    'value' => function ($model) {
                        return EhrHelper::getEnrollSourceById($model['FENROLLSOURCEID']);
                    },
                    'filter' => ArrayHelper::map(\common\models\kingdee\EnrollSource::find()->all(), 'FID', 'FNAME_L2'),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
//            'FRETIREDATE',
//            'FISIMPT',
//            'FZDY1',
//            'FZDY2',
//            'FZDY3',
//            'FZDY4',
//            'FZDY5',
//            'FZDY6',
//            'FZDY7',
//            'FZDY8',
//            'FZDY9',
//            'FZDY10',
//            'FZDY11',
//            'FZDY12',
//            'FZDY13',
//            'FZDY14',
//            'FZDY15',
//            'FZDY16',
//            'FZDY17',
//            'FZDY18',
//            'FZDY19',
//            'FZDY20',
//            'FZDY21',
//            'FZDY22',
//            'FZDY23',
//            'FZDY24',
//            'FZDY25',
//            'FZDY26',
//            'FDIMISSIONREASONID',
                [
                    'attribute' => 'FDIMISSIONREASONID',
                    'label' => Yii::t('app', 'Dimission Reason'),
                    'value' => function ($model) {
                        return EhrHelper::getDimissionReasonById($model['FDIMISSIONREASONID']);
                    },
                    'filter' => ArrayHelper::map(\common\models\kingdee\DimissionReason::find()->all(), 'FID', 'FNAME_L2'),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],

//            'FNEWWORKTIME',
                [
                    'label' => Yii::t('app', 'Work Time'),
                    'attribute' => 'FNEWWORKTIME',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
//            'FEXTWORKTIME',
//            'FLENOFACTUALSERVICE',
//            'FEFFDT',
//            'FLEFFDT',
//            'FHISTORYRELATEID',
//            'FISLEADER',
//            'FLABCONTRACTFIRSTPARTY',
//            'FJOBSEQUENCEID',

                ['class' => 'yii\grid\ActionColumn'],
            ],
        ]);
    } catch (Exception $e) {
    }
    ?>
    <?= $gv ?>
</div>
